package com.dinim.test.objectlibrary;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JComponent;
import javax.swing.JFrame;

import com.dinim.common.StopWatch;
import com.dinim.graphics.GraphicsContextSwingImpl;
import com.dinim.graphics.IGraphicsContext;
import com.dinim.object.Object2D;
import com.dinim.object.Point2D;
import com.dinim.object.Rectangle2D;

public class ObjectTester {

    public static void main(String[] args) {
        
        final JFrame f = new JFrame();

        f.add(new JComponent(){

            
            StopWatch sw = new StopWatch();
            
            Point2D p = new Point2D(60, 60);
            
            public void paint(Graphics g) {
                IGraphicsContext gc = new GraphicsContextSwingImpl(g);
                gc.setAntialiasing(true);

                Random r = new Random();
                
                StopWatch sw2 = new StopWatch();
                sw2.start();
                
                for(int x = 0; x < 1; x++){
                    //sw.start();
                    for(int i = 0; i < 40; i++){
                        Object2D point = new Rectangle2D(r.nextInt(100), r.nextInt(100), r.nextInt(300), r.nextInt(300));
                        point.translate(r.nextInt(50), r.nextInt(50));
                        point.rotate(r.nextInt(100), new Point2D(r.nextInt(100), r.nextInt(100)));
                        point.draw(gc);
                    }
                    //sw.stop();
                    //System.out.println(sw.getElapsedTime());
                    
                    //sw.start();
//                    for(int i = 0; i < 140; i++){
//                        Object2D point = new Rectangle2D(r.nextInt(500), r.nextInt(500), r.nextInt(500), r.nextInt(500));
//                        point.rotate(i, new Point2D(r.nextInt(500), r.nextInt(500)));
//                        point.draw(gc);
//                    }
                    //sw.stop();
                    //System.out.println(sw.getElapsedTime());
                }
                
                sw2.stop();
                System.out.println("Time: " + sw2.getElapsedTime());
                
            }
            
        });

        Rectangle r = new Rectangle(1,1,100,100);
        
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 400);
        f.setVisible(true);
        
        Timer t = new Timer();
        t.schedule(new TimerTask(){

            public void run() {
                System.out.println("doing...");
                //f.repaint();
            }
            
        }, 30, 30);
        
        
        
    }
}
